import './App.css';
import { Switch, Route, Redirect } from 'react-router-dom'
import AboutView from './views/AboutView';
import HomeView from './views/HomeView';
import LoginView from './views/LoginView';
import Auth from "./uitl/uitl"
function App() {
  return (
    <div>
      <Switch>
        <Route exact path="/" component={HomeView} />
        <Route path="/login" component={LoginView} />
        <PrivateRoute authed={Auth} path='/about' component={AboutView} />
      </Switch>
    </div>
  );
}
export default App;
// 路由拦截组件得封装
const PrivateRoute = (props) => {
  const { "component": Com, authed, path } = props;
  console.log(authed.isAuthenticated); // false
  return (
    <Route path={path} render={
      () => {
        return authed.isAuthenticated ? <Com  {...props} /> : <Redirect to={
          {
            pathname: "/login",
            state: { from: props.location }  // 从哪一个页面跳转到登录得
          }
        } />
      }
    }></Route>
  )

}